1692H - Gambling - CodeForces Solution


data structures dp greedy math *1700

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int T;
	cin >> T;
	
	while(T--) {
		int n;
		cin >> n;
		int res = 0, a, l, r;
		map<int, set<pair<int, int>>> M;
		for(int i = 0; i < n; i++) {
			int x;
			cin >> x;
			int sum = 2 * (int)M[x].size() - (i + 1);
			M[x].insert({sum - 1, i});
			auto it = M[x].begin();
			if(sum - it->first > res) {
				res = sum - it->first;
				a = x;
				l = it->second;
				r = i;
			}
		}
		cout << a << ' ' << l + 1 << ' ' << r + 1 << '\n';
		
	}
	
	return 0;
}


Comments

Submit
0 Comments
More Questions

931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test
1108A - Two distinct points
1064A - Make a triangle
1245C - Constanze's Machine
1005A - Tanya and Stairways
1663F - In Every Generation
1108B - Divisors of Two Integers
1175A - From Hero to Zero
1141A - Game 23
1401B - Ternary Sequence
598A - Tricky Sum
519A - A and B and Chess
725B - Food on the Plane
154B - Colliders
127B - Canvas Frames
107B - Basketball Team
245A - System Administrator
698A - Vacations